<!-- 机构端-已收简历 -->
<template>
  <view class="container">
    <!-- 顶部选项卡 -->
    <u-tabs :list="tabList" :current="currentTab" @change="changeTab"></u-tabs>
    
    <!-- 简历列表 -->
    <view v-if="resumeList.length > 0">
      <view v-for="(item, index) in filteredResumes" :key="index" class="resume-item" @click="jlDetails(index)">
        <view class="resume-header">
          <text class="user-name">{{ item.cyinfo.base.jlbi_name }}</text>
          <text class="position">投递：{{ item.gwinfo.gwi_name }}</text>
        </view>
        <view class="resume-info">
          <text>{{ item.cyinfo.base.jlbi_birth }}年 | {{ item.cyinfo.base.jlbi_xueli }} | {{ workTime[index] }}</text>
        </view>
        <view class="resume-footer">
          <text class="time">投递时间：{{ createTiime[index] }}</text>
        </view>
				<view class="resume-status">
					<text class="position">状态：</text>
					<!-- 是否查看 -->
				  <text v-if="item.tdb_state == 0 || item.tdb_state == 1" class="status" :class="{'unviewed': item.jg_isread === 0,
																		'viewed': item.jg_isread === 1,
																		'rejected': item.jg_isread === 2,
																		'interview': item.jg_isread === 3}">
																{{ item.jg_isread == 0 ? '未查看' : '已查看' }}</text>
					<!-- 不合适或邀请 -->
					<text v-else class="status" :class="{'unviewed': item.tdb_state === 0,
																		'viewed': item.tdb_state === 1,
																		'rejected': item.tdb_state === 2,
																		'interview': item.tdb_state === 3}">
																{{ item.tdb_state == 2 ? '不合适' : '已邀请' }}</text>											
				</view>
      </view>
    </view>
    
    <!-- 空状态 -->
    <u-empty v-else mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png"></u-empty>
  </view>
</template>

<script>
import util from '@/utils/util.js'
export default {
  data() {
    return {
      currentTab: 0,
      tabList: [
        { name: '全部' },
        { name: '未查看' },
        { name: '已查看' }
      ],
      resumeList: [
        {
          userName: '用户姓名',
          position: '康养师',
          age: '88',
          education: '大专',
          experience: '6',
          certificate: 'XXXX等级证书',
          deliveryTime: '2025-05-23',
          status: '未查看'
        },
        {
          userName: '用户姓名',
          position: '康养师',
          age: '88',
          education: '大专',
          experience: '6',
          certificate: 'XXXX等级证书',
          deliveryTime: '2025-05-23',
          status: '已查看'
        },
        {
          userName: '用户姓名',
          position: '康养师',
          age: '88',
          education: '大专',
          experience: '6',
          certificate: 'XXXX等级证书',
          deliveryTime: '2025-05-23',
          status: '已邀面试'
        },
        {
          userName: '用户姓名',
          position: '康养师',
          age: '88',
          education: '大专',
          experience: '6',
          certificate: 'XXXX等级证书',
          deliveryTime: '2025-05-23',
          status: '不合适'
        }
      ],
			tdJlData:[],  //根据从业者usercode查询全部个人与企业完整信息
			workTime:[], // 工作年限
			createTiime:[], //投递时间
    }
  },
  computed: {
    filteredResumes() {
      if (this.currentTab === 0) return this.tdJlData
      if (this.currentTab === 1) return this.tdJlData.filter(item => item.jg_isread === 0  && item.tdb_state == 0)
      if (this.currentTab === 2) return this.tdJlData.filter(item => item.jg_isread === 1 || item.tdb_state === 2 || item.tdb_state === 3)
      return this.tdJlData
    },
		// statusText() {
		// 	const statusMap = {
		// 		0: '未查看',
		// 		1: '已查看',
		// 		2: '不合适',
		// 		3: '已邀请'
		// 	}
		// 	return statusMap[this.tdJlData.jg_isread] || '未知状态'
		// }
  },
	onShow() {
		this.$u.api.querytdjl({
			"usercode":uni.getStorageSync('usercode'), ///#机构用户code
			"tdbstate":"" //##1已读，2不合适，3邀请面试			
		}).then(res => {
			console.log('投递简历：', res)
			this.tdJlData = res.data.base_info
			for (var i=0; i< this.tdJlData.length; i++) {
				// 工作年限
				let workYear = util.calculateDateDifference(this.tdJlData[i].cyinfo.base.jlbi_workindate)
				if (workYear.years == 0){
					this.workTime.push(workYear.months+'个月');
				} else 	if(workYear.months == 0){
					this.workTime.push(workYear.years+'年');
				} else if(this.workYear == undefined) {
					this.workTime.push('0月');
				}	else {
					this.workTime.push(workYear.years+'年'+workYear.months+'个月');
				}	
				// 投递时间
				let tdTime = util.formatDate(this.tdJlData[i].gwinfo.create_time)
				this.createTiime.push(tdTime)
				

			}
		})
	},
  methods: {
		// 点击跳转到简历详情
		jlDetails(index) {
			// 更新是否已读状态		
			this.$u.api.updatetdjl({
				tdbcode: this.tdJlData[index].tdb_code,  ///#从业者投递后的简历流程code
				tdbstate: "1"  ///#0未读，1已读，2不合适，3邀请面试
			}).then(res => {
				console.log('改变状态-已读：', res)				
			})
			// 跳转到从业者简历详情
			uni.navigateTo({
				url: `/pages/Institution/invite/online-resume?usercode=${this.tdJlData[index].user_code}&tdbcode=${this.tdJlData[index].tdb_code}`
			});			
		},
		// 切换tab
    changeTab(index) {
      this.currentTab = index
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  padding: 20rpx;
}

.resume-item {
  padding: 30rpx;
	margin-top: 20rpx;
  margin-bottom: 10rpx;
  background-color: #fff;
  border-radius: 10rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}

.resume-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15rpx;
  
  .user-name {
    font-size: 32rpx;
    font-weight: bold;
  }
  
  .position {
    font-size: 28rpx;
    color: #666;
  }
}

.resume-info {
  font-size: 26rpx;
  color: #888;
  margin-bottom: 20rpx;
}

.resume-footer {
  display: flex;
  // justify-content: space-between;
	flex-direction: column;
  font-size: 24rpx;
  color: #999;
	
	.time {
		margin-bottom: 10px;
	}
  

}

.resume-status{
	display: flex;	
	
	.status {
	  &.unviewed {
	    color: #f56c6c;
	  }
	  &.viewed {
	    color: #409eff;
	  }
	  &.interview {
	    color: #67c23a;
	  }
	  &.rejected {
	    color: #909399;
	  }
	}
}
</style>